package za.ac.wits.elen7045.persistence.encryption;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import za.ac.wits.elen7045.persistence.exception.EncryptionException;

public class MD5Encryptor extends OneWayEncryptor {
	
	private final String BYTE_SEPARATOR = "@";

	public MD5Encryptor() throws NoSuchAlgorithmException {
		super(MessageDigest.getInstance("MD5"));
	}

	@Override
	public String encrypt(String text) throws EncryptionException {
	     byte[] encryptedText = getMessageDigest().digest(text.getBytes());
		return getBytesAsSeparatedString(encryptedText, BYTE_SEPARATOR);
	}

}
